library isolate.example.runner_pool;

import 'package:flutter_ability/flutter_ability.dart';

class RunnerPool {
  Future<LoadBalancer> loadBalancer =
      LoadBalancer.create(4, IsolateRunner.spawn);

  /// 方法调用  loadBalancer.run((argument) => null, null);
  Future<int> useLoadBalancer() async {
    final lb = await loadBalancer;
    Future<int> res = lb.run<int, int>(_doSomething, 100);
    return res;
  }

  /// 计算方法
  /// @value 参数
  int _doSomething(int value) {
    int count = 0;
    while (value > 0) {
      count = count + value;
      value--;
    }
    return count;
  }
}
